package modelewithstatemachine;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;



public class ClientAroundStateMachineOMGIMSURROUNDED {
	private double x;
	private double y;
	private double xDest;
	private double yDest;
	private int delaiAttente;
	private boolean prisEnCharge;
	private ManagerWithTaxiWithStateMachinePleaseIWantALongerName manager;
	private ArrayList<TaxiWithStateMachine> taxis;
	
	private static Random generator = new Random();
	
	@SuppressWarnings("unchecked")
	public ClientAroundStateMachineOMGIMSURROUNDED(ManagerWithTaxiWithStateMachinePleaseIWantALongerName manager, ArrayList<TaxiWithStateMachine> taxis) {
		double rClient = generator.nextDouble() * (double)ManagerWithTaxiWithStateMachinePleaseIWantALongerName.getCityRadius();
		double thetaClient = 2D * Math.PI * generator.nextDouble();
		double rDest = generator.nextDouble() * (double)ManagerWithTaxiWithStateMachinePleaseIWantALongerName.getCityRadius();
		double thetaDest = 2D * Math.PI * generator.nextDouble();
		
		x = rClient * Math.cos(thetaClient);
		y = rClient * Math.sin(thetaClient);
		xDest = rDest * Math.cos(thetaDest);
		yDest = rDest * Math.sin(thetaDest);
		
		delaiAttente = (int)(20D * Math.random()) + 1;
		this.manager = manager;
		//this.prisEnCharge = false;
		
		this.taxis = (ArrayList<TaxiWithStateMachine>)taxis.clone();
		Collections.sort(this.taxis, new TaxiComparator(this));
		
		System.out.println("New client : r="+rClient+", theta="+thetaClient);
	}
	
	@SuppressWarnings("unchecked")
	public ClientAroundStateMachineOMGIMSURROUNDED(ManagerWithTaxiWithStateMachinePleaseIWantALongerName manager, int delaiAttente,  ArrayList<TaxiWithStateMachine> taxis) {
		double rClient = generator.nextDouble() * (double)ManagerWithTaxiWithStateMachinePleaseIWantALongerName.getCityRadius();
		double thetaClient = 2D * Math.PI * generator.nextDouble();
		double rDest = generator.nextDouble() * (double)ManagerWithTaxiWithStateMachinePleaseIWantALongerName.getCityRadius();
		double thetaDest = 2D * Math.PI * generator.nextDouble();
		
		x = rClient * Math.cos(thetaClient);
		y = rClient * Math.sin(thetaClient);
		xDest = rDest * Math.cos(thetaDest);
		yDest = rDest * Math.sin(thetaDest);
		
		this.delaiAttente = delaiAttente;
		this.manager = manager;
		//this.prisEnCharge = false;
		
		this.taxis = (ArrayList<TaxiWithStateMachine>)taxis.clone();
		Collections.sort(this.taxis, new TaxiComparator(this));
		
		System.out.println("New client : r="+rClient+", theta="+thetaClient);
	}
	
		
	public void reduireDelaiAttente() {
		this.delaiAttente--;
	}

	public double getX() {
		return x;
	}

	public double getY() {
		return y;
	}
	
	public double getXDest() {
		return xDest;
	}

	public double getYDest() {
		return yDest;
	}

	public int getDelaiAttente() {
		return delaiAttente;
	}
	
	public ArrayList<TaxiWithStateMachine> getSortedTaxis() {
		return taxis;
	}
	
	public boolean isPrisEnCharge() {
		return prisEnCharge;
	}
	
	public void estPrisEnCharge() {
		manager.clientPrisEnCharge(this);
	}
	
	public void estDansTaxi() {
		manager.clientDansTaxi(this);
	}
	
	public void estArrive() {
		manager.clientArrive(this);
	}
}
